# _*_ encoding: utf-8 _*_


class VehicleExtractor:
    def __init__(self, gps_file,save_file):
        self.gps_file = gps_file
        self.save_file = save_file
        self.vehciles = {}
        self.running = False

    def add_observation(self, vechileID):
        assert len(self.vehciles) <= 100
        self.vehciles.setdefault(vechileID, [])

    def start(self):
        self.running = True
        self.run()
        self.save()

    def run(self):
        with open(self.gps_file, "rb") as f:
            for line in f:
                elements = line.strip().split(',')
                if elements[0] in self.vehciles:
                    self.vehciles[elements[0]].append(line)

    def save(self):
        with open(self.save_file, "wb") as f:
            for vehicleID in self.vehciles:
                f.writelines(self.vehciles[vehicleID])


def main():
    gps_file = "../../data/1109/11011607.gps.csv"
    save_file = "../../data/1109/subscript.gps.txt"
    extractor = VehicleExtractor(gps_file, save_file)
    extractor.add_observation("61")
    extractor.add_observation("64")
    extractor.start()

if __name__ == '__main__':
    main()
